﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using StyleMVVM.DependencyInjection;
using StyleMVVM.DependencyInjection.Impl;

namespace StyleMVVM.MVC.DependencyInjection
{
	/// <summary>
	/// Provides a disposal scope for web based applications
	/// </summary>
	[Singleton]
	[Export(typeof(IDefaultDisposalScopeProvider))]
	public class WebDisposalScopeProvider : IDefaultDisposalScopeProvider
	{
		public IDisposalScope ProvideDisposalScope()
		{
			try
			{
				return HttpContext.Current.Items[DisposalScope.DisposalScopeStringKey] as DisposalScope;
			}
			catch (Exception)
			{
			}

			return null;
		}
	}
}
